From 74c89aea8a7dde49bd9e32469b20c1e295f83119 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 13 Nov 2007 00:05:46 +0000 Subject: [PATCH] optimized fishing when looking up existing fish (should perhaps be moved * babl/babl-fish.c: (go_fishing): optimized fishing when looking up existing fish (should perhaps be moved to lists going from given formats, similar to how conversions are added there instead.) Made go_fishing accept BABL_FISH_REFERENCE when source and desintation formats are equal. (babl_fish_process): removed most of the need for BablImage for linear buffers, do a memcpy when source and destination formats are equal (and we're a BABL_FISH_REFERENCE). * babl/babl-db.[ch]: moved the BablDb struct out into public to allow faster iteration through it. svn path=/trunk/; revision=250 --- ChangeLog | 13 +++++++ babl/babl-db.c | 8 ----- babl/babl-db.h | 9 +++++ babl/babl-fish.c | 91 ++++++++++++++---------------------------------- 4 files changed, 49 insertions(+), 72 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c34314..fae4f2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-11-13 Øyvind Kolås + + * babl/babl-fish.c: (go_fishing): optimized fishing when looking + up existing fish (should perhaps be moved to lists going from given + formats, similar to how conversions are added there instead.) Made + go_fishing accept BABL_FISH_REFERENCE when source and desintation + formats are equal. + (babl_fish_process): removed most of the need for BablImage for + linear buffers, do a memcpy when source and destination formats + are equal (and we're a BABL_FISH_REFERENCE). + * babl/babl-db.[ch]: moved the BablDb struct out into public to + allow faster iteration through it. + 2007-11-11 Øyvind Kolås * Modified copyright statement to refer to an URL instead of a civic diff --git a/babl/babl-db.c b/babl/babl-db.c index 3de4e9e..266f8d5 100644 --- a/babl/babl-db.c +++ b/babl/babl-db.c @@ -21,7 +21,6 @@ #include #include "babl-internal.h" -#define HASH_TABLE_SIZE 128 #define DB_INITIAL_SIZE 16 #define DB_INCREMENT_SIZE 16 @@ -35,13 +34,6 @@ static inline int hash (const char *str) return ret; } -typedef struct _BablDb -{ - Babl *hash [HASH_TABLE_SIZE]; - int size; - int count; - Babl **items; -} _BablDb; Babl * babl_db_find (BablDb *db, diff --git a/babl/babl-db.h b/babl/babl-db.h index dfb5911..9c49a3d 100644 --- a/babl/babl-db.h +++ b/babl/babl-db.h @@ -25,6 +25,15 @@ typedef struct _BablDb BablDb; +#define HASH_TABLE_SIZE 128 +typedef struct _BablDb +{ + Babl *hash [HASH_TABLE_SIZE]; + int size; + int count; + Babl **items; +} _BablDb; + BablDb * babl_db_init (void); void babl_db_destroy (BablDb *db); void babl_db_each (BablDb *db, diff --git a/babl/babl-fish.c b/babl/babl-fish.c index ac9cb78..1aa329e 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -55,48 +55,26 @@ babl_fish_db (void) return db; } -typedef struct BablFishingData -{ - Babl *source; - Babl *destination; - Babl *ret; -} BablFishingData; - -static int -fishing_result_examine (Babl *babl, - void *void_data) -{ - BablFishingData *data = void_data; - - if ((void *) data->source == (void *) babl->fish.source && - (void *) data->destination == (void *) babl->fish.destination) - { - data->ret = babl; - /* we do not return BABL_FISH_REFERENCE's since those might exist - * even before a valid BABL_FISH_PATH has been constructed for a - * given conversion. - */ - if (data->ret->class_type == BABL_FISH_REFERENCE) - return 0; - return 1; /* stop iterating */ - } - return 0; /* continue iterating */ -} - -static Babl * +static inline Babl * go_fishing (Babl *source, Babl *destination) { - { - BablFishingData data; + BablDb *db = babl_fish_db (); + int i; - data.source = source; - data.destination = destination; - data.ret = NULL; - - babl_db_each (db, fishing_result_examine, &data); - return data.ret; - } + for (i=0; icount; i++) + { + Babl *item = db->items[i]; + if ((void *) source == (void *) item->fish.source && + (void *) destination == (void *) item->fish.destination && + (item->class_type != BABL_FISH_REFERENCE || + source == destination) + ) + { + return item; + } + } + return NULL; } Babl * @@ -142,7 +120,7 @@ babl_fish (void *source, return NULL; } - if(1){ + { Babl *lucky; lucky = go_fishing (source_format, destination_format); if (lucky) @@ -184,8 +162,6 @@ babl_fish_process (Babl *babl, void *destination, long n) { - BablImage *source_image = NULL; - BablImage *destination_image = NULL; long ret = 0; switch (babl->class_type) @@ -193,25 +169,17 @@ babl_fish_process (Babl *babl, case BABL_FISH_REFERENCE: case BABL_FISH_SIMPLE: case BABL_FISH_PATH: - -#if 0 - if (BABL_IS_BABL (source)) - source_image = source; -#endif - if (!source_image) - source_image = (BablImage *) babl_image_from_linear ( - source, (Babl *) babl->fish.source); -#if 0 - if (BABL_IS_BABL (destination)) - destination_image = destination; -#endif - if (!destination_image) - destination_image = (BablImage *) babl_image_from_linear ( - destination, (Babl *) babl->fish.destination); - if (babl->class_type == BABL_FISH_REFERENCE) { - ret = babl_fish_reference_process (babl, source, destination, n); + if (babl->fish.source == babl->fish.destination) + { /* XXX: we're assuming linear buffers */ + memcpy (source, destination, n * babl->fish.source->format.bytes_per_pixel); + ret = n; + } + else + { + ret = babl_fish_reference_process (babl, source, destination, n); + } } else if (babl->class_type == BABL_FISH_PATH) { @@ -226,15 +194,10 @@ babl_fish_process (Babl *babl, } else { - ret = babl_conversion_process (BABL (babl->fish_simple.conversion), - (char *) source_image, (char *) destination_image, n); + babl_assert (0); } } - - babl_free (source_image); - babl_free (destination_image); break; - default: babl_log ("NYI"); ret = -1; -- 2.30.2